package com.zx.tradeclient.ctrl.index5;

import java.util.ArrayList;
import java.util.List;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;

import com.zx.base.crop.Crop;
import com.zx.base.ctrl.BaseActivity;
import com.zx.base.util.ActivityTaskManager;
import com.zx.base.widget.SlidingPage;
import com.zx.base.widget.SlidingPage.SlidingPagerAdapter;
import com.zx.base.widget.SlidingPage.ViewPagerSelectListener;
import com.zx.tradeclient.R;

public class DetialPageActivity extends BaseActivity implements OnClickListener {
	/** Called when the activity is first created. */

	private SlidingPage page;
	private LinearLayout page_layout;

	private CompanyDetailInfo detailinfo;
	private CompanyRewardInfo rewardinfo;
	private GoodsList goodslist;
	private MessagesList messagelist;

	private Crop crop;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.listindex);

		if (!(ActivityTaskManager.getInstance().containsName("Index2Activity"))) {
			ActivityTaskManager.getInstance().putActivity("Index2Activity",
					this);
		}
		crop = new Crop(this);
		init();
	}

	private void init() {

		LayoutInflater mInflater = getLayoutInflater();
		String[] titles = new String[] { "公司资料", "公司资质", "产品信息", "留言板" };
		page = new SlidingPage(this, 4, R.drawable.page_slider_4);
		page.setTitles(titles);
		setHeader(1);
		page_layout = (LinearLayout) findViewById(R.id.list_main_layout);
		page_layout.addView(page);

		final List<View> listViews = new ArrayList<View>();
		listViews.add(mInflater.inflate(R.layout.company_info_edit, null));
		listViews.add(mInflater.inflate(R.layout.user_license, null));
		listViews.add(mInflater.inflate(R.layout.list, null));
		listViews.add(mInflater.inflate(R.layout.list, null));
		page.getViewPager().setAdapter(new SlidingPagerAdapter(listViews));

		page.setViewPageSelectedListener(new ViewPagerSelectListener() {

			@Override
			public void pageSelected(int current) {
				View view = listViews.get(current);
				switch (current) {
				case 0:
					setHeader(1);
					if (detailinfo == null)
						detailinfo = new CompanyDetailInfo(
								DetialPageActivity.this, view);
					detailinfo.init();
					break;
				case 1:
					setHeader(1);
					if (rewardinfo == null)
						rewardinfo = new CompanyRewardInfo(
								DetialPageActivity.this, view, crop);
					rewardinfo.init();
					break;
				case 2:
					setHeader(2);
					if (goodslist == null)
						goodslist = new GoodsList(DetialPageActivity.this, view);
					goodslist.init();
					break;
				case 3:
					setHeader(0);
					if (messagelist == null)
						messagelist = new MessagesList(DetialPageActivity.this,
								view);
					break;
				default:
					break;
				}

			}
		});

		page.getViewPager().setCurrentItem(0, false);
		page.getViewPageSelectedListener().pageSelected(0);

	}
	
	@Override
	protected void onResume() {
		if (goodslist != null)
			goodslist.refresh();
		
		super.onResume();
	}

	public void onClick(View v) {
		// TODO Auto-generated method stub
		if (v == header_left) {

		} else if (v == header_right) {

		}

	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		crop.onActivityResult(requestCode, resultCode, data);
	}

}